package buoi1_hocsinh;

public class HocSinh {
	private String maso;
	private String hoten;
	private float diemtb;
	public String getMaso() {
		return maso;
	}//tao cap get and set in tool source of eclipse
	public void setMaso(String maso) {
		this.maso = maso;
	}
	public String getHoten() {
		return hoten;
	}
	public void setHoten(String hoten) {
		this.hoten = hoten;
	}
	public float getDiemtb() {
		return diemtb;
	}
	//method cho moi hanh vi
	public void setDiemtb(float diemtb) throws Exception{
		if (diemtb<0||diemtb>10)
			throw new Exception("Diem khong hop le");
		this.diemtb = diemtb;
	}
	// tao cac constructor: tham so hoac khong tham so generate con field
	public HocSinh(String maso, String hoten, float diemtb) {
		super();
		this.maso = maso;
		this.hoten = hoten;
		this.diemtb = diemtb;
	}
	public HocSinh() throws Exception{
		this("no-id","no-name", 0f);
		// TODO Auto-generated constructor stub
	}
	public String rank(){
		if (diemtb>=9)
			return "xuat sac";
		else if (diemtb>=8)
			return "gioi";
		else if (diemtb>=7)
			return "kha";
		else if (diemtb>=6)
			return "tb kha";
		else if (diemtb>=5)
			return "trung binh";
		else if (diemtb>=4)
			return "yeu";
		else 
			return "kem";
	}
	// overrive phuong thuc maso
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((maso == null) ? 0 : maso.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		HocSinh other = (HocSinh) obj;
		if (maso == null) {
			if (other.maso != null)
				return false;
		} else if (!maso.equalsIgnoreCase(other.maso))
			return false;
		return true;
	}
	//override Generate to String
	@Override
	public String toString() {
		return hoten+" xep loai "+ rank();
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	

}
